package com.cs171.market.mapper;

import com.cs171.market.entity.Good;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Endy
 * @create 2020 - 06 - 21 - 17:21
 * @date 2020/6/21 - 17:21
 */
@Mapper
public interface GoodMapper {

    @Select("Select gid, gname, gprice, gnum, weight, addTime FROM good")
    Page<Good> getAllGoodList();

    @Select("Select gid, gname, gprice, gnum, weight, addTime FROM good WHERE gname LIKE #{query}")
    Page<Good> searchGoodList(String query);

    @Select("Select COUNT(*) FROM good")
    String countGood();

    @Select("Insert INTO good (gname, gcat_id, gprice, gnum, weight, gdesc, gimg, gdate) VALUE(#{name}, #{cat}, #{price}, #{number}, #{weight}, #{introduce}, #{pics}, #{time})")
    void addGoodAll(String name,Integer cat, Integer price, Integer number, Integer weight, String introduce, String pics, long time);

    @Select("Select MAX(gid) FROM good")
    Integer getNewGoodId();

    @Select("Select gid, gname, gprice, gdesc, gnum, weight, gdate, gcat_id FROM good WHERE gid = #{id}")
    Good responsToAdd(Integer id);

    @Select("Select gid, gname, gprice, gnum, weight, gdate FROM good WHERE gid = #{id}")
    Good getGoodById(Integer id);

    @Select("Update good SET gname = #{name}, gprice = #{price}, gnum = #{number}, weight = #{weight} WHERE gid = #{id}")
    void updateGood(Integer id, String name, Integer price, Integer number, Integer weight);

    @Select("Delete FROM good WHERE gid=#{id}")
    void deleteGood(Integer id);
}
